class Solution {
public:
    int longestConsecutive(vector<int>& nums) {
        if(nums.size() == 0) return 0;
        unordered_set<int> hash;
        for (const int& num : nums) {
            hash.insert(num);
        }
        int ret = 1;
        
        for(const int& n : nums){
            if(!hash.count(n-1)){
                int ans = 1;
                int cur = n;
                while(hash.count(cur+1)){
                    cur = cur+1;
                    ans += 1;
                }
                ret = max(ret,ans);
            }
        }
        return ret;
    }
};
